home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Tool Chest / Development Tools & Languages / • Other Platforms / PCCTS 1.31 / h / err.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-10  |  17.9 KB  |  862 lines  |  [TEXT/MPS ]

  1. /*
  2.  * err.h
  3.  *
  4.  * Standard error handling mechanism
  5.  *
  6.  * SOFTWARE RIGHTS
  7.  *
  8.  * We reserve no LEGAL rights to the Purdue Compiler Construction Tool
  9.  * Set (PCCTS) -- PCCTS is in the public domain.  An individual or
  10.  * company may do whatever they wish with source code distributed with
  11.  * PCCTS or the code generated by PCCTS, including the incorporation of
  12.  * PCCTS, or its output, into commerical software.
  13.  * 
  14.  * We encourage users to develop software with PCCTS.  However, we do ask
  15.  * that credit is given to us for developing PCCTS.  By "credit",
  16.  * we mean that if you incorporate our source code into one of your
  17.  * programs (commercial product, research project, or otherwise) that you
  18.  * acknowledge this fact somewhere in the documentation, research report,
  19.  * etc...  If you like PCCTS and have developed a nice tool with the
  20.  * output, please mention that you developed it using PCCTS.  In
  21.  * addition, we ask that this header remain intact in our source code.
  22.  * As long as these guidelines are kept, we expect to continue enhancing
  23.  * this system and expect to make other tools available as they are
  24.  * completed.
  25.  *
  26.  * Has grown to hold all kinds of stuff (err.h is increasingly misnamed)
  27.  *
  28.  * ANTLR 1.31
  29.  * Terence Parr
  30.  * Parr Research Corporation
  31.  * with Purdue University and AHPCRC, University of Minnesota
  32.  * 1989-1995
  33.  */
  34.  
  35. #ifndef ERR_H
  36. #define ERR_H
  37.  
  38. #include "config.h"
  39.  
  40. #include <string.h>
  41. #ifdef __STDC__
  42. #include <stdarg.h>
  43. #else
  44. #include <varargs.h>
  45. #endif
  46.  
  47. #ifdef DUM
  48. /* Define usable bits per unsigned int word (used for set stuff) */
  49. #ifdef PC
  50. #define BSETWORDSIZE 16
  51. #define BSETLOGWORDSIZE    4
  52. #else
  53. #define    BSETWORDSIZE 32
  54. #define BSETLOGWORDSIZE 5
  55. #endif
  56. #endif
  57.  
  58. #define    BSETWORDSIZE 8
  59. #define BSETLOGWORDSIZE 3        /* SetWordType is 8bits */
  60.  
  61. #define    BSETMODWORD(x) ((x) & (BSETWORDSIZE-1))        /* x % BSETWORDSIZE */
  62. #define    BSETDIVWORD(x) ((x) >> BSETLOGWORDSIZE)        /* x / BSETWORDSIZE */
  63.  
  64. /* This is not put into the global pccts_parser structure because it is
  65.  * hidden and does not need to be saved during a "save state" operation
  66.  */
  67. /* maximum of 32 bits/unsigned int and must be 8 bits/byte */
  68. static SetWordType bitmask[] = {
  69.     0x00000001, 0x00000002, 0x00000004, 0x00000008,
  70.     0x00000010, 0x00000020, 0x00000040, 0x00000080
  71. };
  72.  
  73. void
  74. #ifdef __USE_PROTOS
  75. zzresynch(SetWordType *wd,SetWordType mask)
  76. #else
  77. zzresynch(wd,mask)
  78. SetWordType *wd, mask;
  79. #endif
  80. {
  81.     static int consumed = 1;
  82.  
  83.     /* if you enter here without having consumed a token from last resynch
  84.      * force a token consumption.
  85.      */
  86.     if ( !consumed ) {zzCONSUME; return;}
  87.  
  88.     /* if current token is in resynch set, we've got what we wanted */
  89.     if ( wd[LA(1)]&mask || LA(1) == zzEOF_TOKEN ) {consumed=0; return;}
  90.     
  91.     /* scan until we find something in the resynch set */
  92.     while ( !(wd[LA(1)]&mask) && LA(1) != zzEOF_TOKEN ) {zzCONSUME;}
  93.     consumed=1;
  94. }
  95.  
  96. void
  97. #ifdef __USE_PROTOS
  98. zzconsumeUntil(SetWordType *st)
  99. #else
  100. zzconsumeUntil(st)
  101. SetWordType *st;
  102. #endif
  103. {
  104.     while ( !zzset_el(LA(1), st) ) { zzCONSUME; }
  105. }
  106.  
  107. void
  108. #ifdef __USE_PROTOS
  109. zzconsumeUntilToken(int t)
  110. #else
  111. zzconsumeUntilToken(t)
  112. int t;
  113. #endif
  114. {
  115.     while ( LA(1)!=t ) { zzCONSUME; }
  116. }
  117.  
  118. /* input looks like:
  119.  *        zzFAIL(k, e1, e2, ...,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText)
  120.  * where the zzMiss stuff is set here to the token that did not match
  121.  * (and which set wasn't it a member of).
  122.  */
  123. void
  124. #ifdef __USE_PROTOS
  125. zzFAIL(int k, ...)
  126. #else
  127. zzFAIL(va_alist)
  128. va_dcl
  129. #endif
  130. {
  131. #ifdef LL_K
  132.     static char text[LL_K*ZZLEXBUFSIZE+1];
  133.     SetWordType *f[LL_K];
  134. #else
  135.     static char text[ZZLEXBUFSIZE+1];
  136.     SetWordType *f[1];
  137. #endif
  138.     SetWordType **miss_set;
  139.     char **miss_text;
  140.     int *bad_tok;
  141.     char **bad_text;
  142.     int *err_k;
  143.     int i;
  144.     va_list ap;
  145. #ifndef __USE_PROTOS
  146.     int k;
  147. #endif
  148. #ifdef __USE_PROTOS
  149.     va_start(ap, k);
  150. #else
  151.     va_start(ap);
  152.     k = va_arg(ap, int);    /* how many lookahead sets? */
  153. #endif
  154.     text[0] = '\0';
  155.     for (i=1; i<=k; i++)    /* collect all lookahead sets */
  156.     {
  157.         f[i-1] = va_arg(ap, SetWordType *);
  158.     }
  159.     for (i=1; i<=k; i++)    /* look for offending token */
  160.     {
  161.         if ( i>1 ) strcat(text, " ");
  162.         strcat(text, LATEXT(i));
  163.         if ( !zzset_el((unsigned)LA(i), f[i-1]) ) break;
  164.     }
  165.     miss_set = va_arg(ap, SetWordType **);
  166.     miss_text = va_arg(ap, char **);
  167.     bad_tok = va_arg(ap, int *);
  168.     bad_text = va_arg(ap, char **);
  169.     err_k = va_arg(ap, int *);
  170.     if ( i>k )
  171.     {
  172.         /* bad; lookahead is permutation that cannot be matched,
  173.          * but, the ith token of lookahead is valid at the ith position
  174.          * (The old LL sub 1 (k) versus LL(k) parsing technique)
  175.          */
  176.         *miss_set = NULL;
  177.         *miss_text = zzlextext;
  178.         *bad_tok = LA(1);
  179.         *bad_text = LATEXT(1);
  180.         *err_k = k;
  181.         return;
  182.     }
  183. /*    fprintf(stderr, "%s not in %dth set\n", zztokens[LA(i)], i);*/
  184.     *miss_set = f[i-1];
  185.     *miss_text = text;
  186.     *bad_tok = LA(i);
  187.     *bad_text = LATEXT(i);
  188.     if ( i==1 ) *err_k = 1;
  189.     else *err_k = k;
  190. }
  191.  
  192. void
  193. #ifdef __USE_PROTOS
  194. zzsave_antlr_state(zzantlr_state *buf)
  195. #else
  196. zzsave_antlr_state(buf)
  197. zzantlr_state *buf;
  198. #endif
  199. {
  200. #ifdef LL_K
  201.     int i;
  202. #endif
  203.  
  204. #ifdef ZZCAN_GUESS
  205.     buf->guess_start = zzguess_start;
  206.     buf->guessing = zzguessing;
  207. #endif
  208.     buf->asp = zzasp;
  209. #ifdef GENAST
  210.     buf->ast_sp = zzast_sp;
  211. #endif
  212. #ifdef ZZINF_LOOK
  213.     buf->inf_labase = zzinf_labase;
  214.     buf->inf_last = zzinf_last;
  215. #endif
  216. #ifdef DEMAND_LOOK
  217.     buf->dirty = zzdirty;
  218. #endif
  219. #ifdef LL_K
  220.     for (i=0; i<LL_K; i++) buf->tokenLA[i] = zztokenLA[i];
  221.     for (i=0; i<LL_K; i++) strcpy(buf->textLA[i], zztextLA[i]);
  222.     buf->lap = zzlap;
  223.     buf->labase = zzlabase;
  224. #else
  225.     buf->token = zztoken;
  226.     strcpy(buf->text, zzlextext);
  227. #endif
  228. }
  229.  
  230. void
  231. #ifdef __USE_PROTOS
  232. zzrestore_antlr_state(zzantlr_state *buf)
  233. #else
  234. zzrestore_antlr_state(buf)
  235. zzantlr_state *buf;
  236. #endif
  237. {
  238. #ifdef LL_K
  239.     int i;
  240. #endif
  241.  
  242. #ifdef ZZCAN_GUESS
  243.     zzguess_start = buf->guess_start;
  244.     zzguessing = buf->guessing;
  245. #endif
  246.     zzasp = buf->asp;
  247. #ifdef GENAST
  248.     zzast_sp = buf->ast_sp;
  249. #endif
  250. #ifdef ZZINF_LOOK
  251.     zzinf_labase = buf->inf_labase;
  252.     zzinf_last = buf->inf_last;
  253. #endif
  254. #ifdef DEMAND_LOOK
  255.     zzdirty = buf->dirty;
  256. #endif
  257. #ifdef LL_K
  258.     for (i=0; i<LL_K; i++) zztokenLA[i] = buf->tokenLA[i];
  259.     for (i=0; i<LL_K; i++) strcpy(zztextLA[i], buf->textLA[i]);
  260.     zzlap = buf->lap;
  261.     zzlabase = buf->labase;
  262. #else
  263.     zztoken = buf->token;
  264.     strcpy(zzlextext, buf->text);
  265. #endif
  266. }
  267.  
  268. void
  269. #ifdef __USE_PROTOS
  270. zzedecode(SetWordType *a)
  271. #else
  272. zzedecode(a)
  273. SetWordType *a;
  274. #endif
  275. {
  276.     register SetWordType *p = a;
  277.     register SetWordType *endp = &(p[zzSET_SIZE]);
  278.     register unsigned e = 0;
  279.  
  280.     if ( zzset_deg(a)>1 ) fprintf(stderr, " {");
  281.     do {
  282.         register SetWordType t = *p;
  283.         register SetWordType *b = &(bitmask[0]);
  284.         do {
  285.             if ( t & *b ) fprintf(stderr, " %s", zztokens[e]);
  286.             e++;
  287.         } while (++b < &(bitmask[sizeof(SetWordType)*8]));
  288.     } while (++p < endp);
  289.     if ( zzset_deg(a)>1 ) fprintf(stderr, " }");
  290. }
  291.  
  292. #ifndef USER_ZZSYN
  293. /* standard error reporting function */
  294. void
  295. #ifdef __USE_PROTOS
  296. zzsyn(char *text, int tok, char *egroup, SetWordType *eset, int etok, int k, char *bad_text)
  297. #else
  298. zzsyn(text, tok, egroup, eset, etok, k, bad_text)
  299. char *text, *egroup, *bad_text;
  300. int tok;
  301. int etok;
  302. int k;
  303. SetWordType *eset;
  304. #endif
  305. {
  306.     
  307.     fprintf(stderr, "line %d: syntax error at \"%s\"", zzline, (tok==zzEOF_TOKEN)?"EOF":bad_text);
  308.     if ( !etok && !eset ) {fprintf(stderr, "\n"); return;}
  309.     if ( k==1 ) fprintf(stderr, " missing");
  310.     else
  311.     {
  312.         fprintf(stderr, "; \"%s\" not", bad_text);
  313.         if ( zzset_deg(eset)>1 ) fprintf(stderr, " in");
  314.     }
  315.     if ( zzset_deg(eset)>0 ) zzedecode(eset);
  316.     else fprintf(stderr, " %s", zztokens[etok]);
  317.     if ( strlen(egroup) > 0 ) fprintf(stderr, " in %s", egroup);
  318.     fprintf(stderr, "\n");
  319. }
  320. #endif
  321.  
  322. /* is b an element of set p? */
  323. int
  324. #ifdef __USE_PROTOS
  325. zzset_el(unsigned b, SetWordType *p)
  326. #else
  327. zzset_el(b,p)
  328. unsigned b;
  329. SetWordType *p;
  330. #endif
  331. {
  332.     return( p[BSETDIVWORD(b)] & bitmask[BSETMODWORD(b)] );
  333. }
  334.  
  335. int
  336. #ifdef __USE_PROTOS
  337. zzset_deg(SetWordType *a)
  338. #else
  339. zzset_deg(a)
  340. SetWordType *a;
  341. #endif
  342. {
  343.     /* Fast compute degree of a set... the number
  344.        of elements present in the set.  Assumes
  345.        that all word bits are used in the set
  346.     */
  347.     register SetWordType *p = a;
  348.     register SetWordType *endp = &(a[zzSET_SIZE]);
  349.     register int degree = 0;
  350.  
  351.     if ( a == NULL ) return 0;
  352.     while ( p < endp )
  353.     {
  354.         register SetWordType t = *p;
  355.         register SetWordType *b = &(bitmask[0]);
  356.         do {
  357.             if (t & *b) ++degree;
  358.         } while (++b < &(bitmask[sizeof(SetWordType)*8]));
  359.         p++;
  360.     }
  361.  
  362.     return(degree);
  363. }
  364.  
  365. #ifdef DEMAND_LOOK
  366.  
  367. #ifdef LL_K
  368. int
  369. #ifdef __USE_PROTOS
  370. _zzmatch(int _t, char **zzBadText, char **zzMissText,
  371.         int *zzMissTok, int *zzBadTok,
  372.         SetWordType **zzMissSet)
  373. #else
  374. _zzmatch(_t, zzBadText, zzMissText, zzMissTok, zzBadTok, zzMissSet)
  375. int _t;
  376. char **zzBadText;
  377. char **zzMissText;
  378. int *zzMissTok, *zzBadTok;
  379. SetWordType **zzMissSet;
  380. #endif
  381. {
  382.     if ( zzdirty==LL_K ) {
  383.         zzCONSUME;
  384.     }
  385.     if ( LA(1)!=_t ) {
  386.         *zzBadText = *zzMissText=LATEXT(1);    
  387.         *zzMissTok= _t; *zzBadTok=LA(1); 
  388.         *zzMissSet=NULL;                
  389.         return 0;
  390.     }
  391.     zzMakeAttr                        
  392.     zzdirty++;                        
  393.     zzlabase++;                        
  394.     return 1;
  395. }
  396.  
  397. int
  398. #ifdef __USE_PROTOS
  399. _zzmatch_wsig(int _t)
  400. #else
  401. _zzmatch_wsig(_t)
  402. int _t;
  403. #endif
  404. {
  405.     if ( zzdirty==LL_K ) {
  406.         zzCONSUME;
  407.     }
  408.     if ( LA(1)!=_t ) {
  409.         return 0;
  410.     }
  411.     zzMakeAttr                        
  412.     zzdirty++;                        
  413.     zzlabase++;                        
  414.     return 1;
  415. }
  416.  
  417. #else
  418.  
  419. int
  420. #ifdef __USE_PROTOS
  421. _zzmatch(int _t, char **zzBadText, char **zzMissText,
  422.          int *zzMissTok, int *zzBadTok, SetWordType **zzMissSet)
  423. #else
  424. _zzmatch(_t, zzBadText, zzMissText, zzMissTok, zzBadTok, zzMissSet)
  425. int _t;
  426. char **zzBadText;
  427. char **zzMissText;
  428. int *zzMissTok, *zzBadTok;
  429. SetWordType **zzMissSet;
  430. #endif
  431. {                                
  432.     if ( zzdirty ) {zzCONSUME;}        
  433.     if ( LA(1)!=_t ) {
  434.         *zzBadText = *zzMissText=LATEXT(1);    
  435.         *zzMissTok= _t; *zzBadTok=LA(1); 
  436.         *zzMissSet=NULL;                
  437.         return 0;
  438.     }                                
  439.     zzdirty = 1;                    
  440.     zzMakeAttr                        
  441.     return 1;
  442. }
  443.  
  444. int
  445. #ifdef __USE_PROTOS
  446. _zzmatch_wsig(int _t)
  447. #else
  448. _zzmatch_wsig(_t)
  449. int _t;
  450. #endif
  451. {
  452.     if ( zzdirty ) {zzCONSUME;}        
  453.     if ( LA(1)!=_t ) {
  454.         return 0;
  455.     }
  456.     zzdirty = 1;                    
  457.     zzMakeAttr                        
  458.     return 1;
  459. }
  460.  
  461. #endif /*LL_K*/
  462.  
  463. #else
  464.  
  465. int
  466. #ifdef __USE_PROTOS
  467. _zzmatch(int _t, char **zzBadText, char **zzMissText,
  468.         int *zzMissTok, int *zzBadTok,
  469.         SetWordType **zzMissSet)
  470. #else
  471. _zzmatch(_t, zzBadText, zzMissText, zzMissTok, zzBadTok, zzMissSet)
  472. int _t;
  473. char **zzBadText;
  474. char **zzMissText;
  475. int *zzMissTok, *zzBadTok;
  476. SetWordType **zzMissSet;
  477. #endif
  478. {
  479.     if ( LA(1)!=_t ) {                
  480.         *zzBadText = *zzMissText=LATEXT(1);    
  481.         *zzMissTok= _t; *zzBadTok=LA(1); 
  482.         *zzMissSet=NULL;                
  483.         return 0;
  484.     }
  485.     zzMakeAttr
  486.     return 1;
  487. }
  488.  
  489. int
  490. #ifdef __USE_PROTOS
  491. _zzmatch_wsig(int _t)
  492. #else
  493. _zzmatch_wsig(_t)
  494. int _t;
  495. #endif
  496. {
  497.     if ( LA(1)!=_t ) return 0;
  498.     zzMakeAttr                        
  499.     return 1;
  500. }
  501.  
  502. #endif /*DEMAND_LOOK*/
  503.  
  504. #ifdef ZZINF_LOOK
  505. void
  506. #ifdef __USE_PROTOS
  507. _inf_zzgettok(void)
  508. #else
  509. _inf_zzgettok()
  510. #endif
  511. {
  512.     if ( zzinf_labase >= zzinf_last )                    
  513.         {NLA = zzEOF_TOKEN; strcpy(NLATEXT, "");}    
  514.     else {                                            
  515.         NLA = zzinf_tokens[zzinf_labase];
  516.         zzline = zzinf_line[zzinf_labase];    /* wrong in 1.21 */
  517.         strcpy(NLATEXT, zzinf_text[zzinf_labase]);        
  518.         zzinf_labase++;                                 
  519.     }                                                
  520. }
  521. #endif
  522.  
  523. #ifdef ZZINF_LOOK
  524. /* allocate default size text,token and line arrays;
  525.  * then, read all of the input reallocing the arrays as needed.
  526.  * Once the number of total tokens is known, the LATEXT(i) array (zzinf_text)
  527.  * is allocated and it's pointers are set to the tokens in zzinf_text_buffer.
  528.  */
  529. void
  530. #ifdef __USE_PROTOS
  531. zzfill_inf_look(void)
  532. #else
  533. zzfill_inf_look()
  534. #endif
  535. {
  536.     int tok, line;
  537.     int zzinf_token_buffer_size = ZZINF_DEF_TOKEN_BUFFER_SIZE;
  538.     int zzinf_text_buffer_size = ZZINF_DEF_TEXT_BUFFER_SIZE;
  539.     int zzinf_text_buffer_index = 0;
  540.     int zzinf_lap = 0;
  541.  
  542.     /* allocate text/token buffers */
  543.     zzinf_text_buffer = (char *) malloc(zzinf_text_buffer_size);
  544.     if ( zzinf_text_buffer == NULL )
  545.     {
  546.         fprintf(stderr, "cannot allocate lookahead text buffer (%d bytes)\n", 
  547.         zzinf_text_buffer_size);
  548.         exit(-1);                                        
  549.     }
  550.     zzinf_tokens = (int *) calloc(zzinf_token_buffer_size,sizeof(int)); 
  551.     if ( zzinf_tokens == NULL )
  552.     {
  553.         fprintf(stderr,    "cannot allocate token buffer (%d tokens)\n", 
  554.                 zzinf_token_buffer_size);
  555.         exit(-1);                                        
  556.     }
  557.     zzinf_line = (int *) calloc(zzinf_token_buffer_size,sizeof(int));
  558.     if ( zzinf_line == NULL )
  559.     {
  560.         fprintf(stderr, "cannot allocate line buffer (%d ints)\n",
  561.                 zzinf_token_buffer_size);
  562.         exit(-1);
  563.     }
  564.  
  565.     /* get tokens, copying text to text buffer */
  566.     zzinf_text_buffer_index = 0;
  567.     do {
  568.         zzgettok();
  569.         line = zzreal_line;
  570.         while ( zzinf_lap>=zzinf_token_buffer_size )
  571.         {
  572.             zzinf_token_buffer_size += ZZINF_BUFFER_TOKEN_CHUNK_SIZE; 
  573.             zzinf_tokens = (int *) realloc(zzinf_tokens,
  574.                                                  zzinf_token_buffer_size*sizeof(int));
  575.             if ( zzinf_tokens == NULL )
  576.             {
  577.                 fprintf(stderr, "cannot allocate lookahead token buffer (%d tokens)\n", 
  578.                         zzinf_token_buffer_size);
  579.                 exit(-1);
  580.             }
  581.             zzinf_line = (int *) realloc(zzinf_line,
  582.                                          zzinf_token_buffer_size*sizeof(int));
  583.             if ( zzinf_line == NULL )
  584.             {
  585.                 fprintf(stderr, "cannot allocate lookahead line buffer (%d ints)\n",
  586.                         zzinf_token_buffer_size);
  587.                 exit(-1);
  588.             }
  589.  
  590.         }
  591.         while ( (zzinf_text_buffer_index+strlen(NLATEXT)+1) >= zzinf_text_buffer_size )
  592.         {
  593.             zzinf_text_buffer_size += ZZINF_BUFFER_TEXT_CHUNK_SIZE; 
  594.             zzinf_text_buffer = (char *) realloc(zzinf_text_buffer,
  595.                                                  zzinf_text_buffer_size);
  596.             if ( zzinf_text_buffer == NULL )
  597.             {
  598.                 fprintf(stderr,    "cannot allocate lookahead text buffer (%d bytes)\n", 
  599.                         zzinf_text_buffer_size);
  600.                 exit(-1);
  601.             }
  602.         }
  603.         /* record token and text and line of input symbol */
  604.         tok = zzinf_tokens[zzinf_lap] = NLA;
  605.         strcpy(&zzinf_text_buffer[zzinf_text_buffer_index], NLATEXT);
  606.         zzinf_text_buffer_index += strlen(NLATEXT)+1;
  607.         zzinf_line[zzinf_lap] = line;
  608.         zzinf_lap++;
  609.     } while (tok!=zzEOF_TOKEN);
  610.     zzinf_labase = 0;
  611.     zzinf_last = zzinf_lap-1;
  612.  
  613.     /* allocate ptrs to text of ith token */
  614.     zzinf_text = (char **) calloc(zzinf_last+1,sizeof(char *));
  615.     if ( zzinf_text == NULL )
  616.     {
  617.         fprintf(stderr,    "cannot allocate lookahead text buffer (%d)\n", 
  618.                 zzinf_text_buffer_size); 
  619.         exit(-1);                                            
  620.     }                                                        
  621.     zzinf_text_buffer_index = 0;
  622.     zzinf_lap = 0;
  623.     /* set ptrs so that zzinf_text[i] is the text of the ith token found on input */
  624.     while (zzinf_lap<=zzinf_last)
  625.     {
  626.         zzinf_text[zzinf_lap++] = &zzinf_text_buffer[zzinf_text_buffer_index]; 
  627.         zzinf_text_buffer_index += strlen(&zzinf_text_buffer[zzinf_text_buffer_index])+1; 
  628.     }
  629. }
  630. #endif
  631.  
  632. int
  633. #ifdef __USE_PROTOS
  634. _zzsetmatch(SetWordType *e, char **zzBadText, char **zzMissText,
  635.             int *zzMissTok, int *zzBadTok,
  636.             SetWordType **zzMissSet)
  637. #else
  638. _zzsetmatch(e, zzBadText, zzMissText, zzMissTok, zzBadTok, zzMissSet)
  639. SetWordType *e;
  640. char **zzBadText;
  641. char **zzMissText;
  642. int *zzMissTok, *zzBadTok;
  643. SetWordType **zzMissSet;
  644. #endif
  645. {
  646. #ifdef DEMAND_LOOK
  647. #ifdef LL_K
  648.     if ( zzdirty==LL_K ) {zzCONSUME;}
  649. #else
  650.     if ( zzdirty ) {zzCONSUME;}
  651. #endif
  652. #endif
  653.     if ( !zzset_el((unsigned)LA(1), e) ) {
  654.         *zzBadText = LATEXT(1); *zzMissText=NULL;
  655.         *zzMissTok= 0; *zzBadTok=LA(1);
  656.         *zzMissSet=e;
  657.         return 0;
  658.     }
  659. #ifdef DEMAND_LOOK
  660. #ifdef LL_K
  661.     zzdirty++;
  662. #else
  663.     zzdirty = 1;
  664. #endif
  665. #endif
  666.     zzMakeAttr
  667.     return 1;
  668. }
  669.  
  670. int
  671. #ifdef __USE_PROTOS
  672. _zzmatch_wdfltsig(int tokenWanted, SetWordType *whatFollows)
  673. #else
  674. _zzmatch_wdfltsig(tokenWanted, whatFollows)
  675. int tokenWanted;
  676. SetWordType *whatFollows;
  677. #endif
  678. {
  679. #ifdef DEMAND_LOOK
  680. #ifdef LL_K
  681.     if ( zzdirty==LL_K ) {
  682.             zzCONSUME;
  683.     }
  684. #else
  685.     if ( zzdirty ) {zzCONSUME;}
  686. #endif
  687. #endif
  688.  
  689.     if ( LA(1)!=tokenWanted )
  690.     {
  691.         fprintf(stderr,
  692.                 "line %d: syntax error at \"%s\" missing %s\n",
  693.                 zzline,
  694.                 (LA(1)==zzEOF_TOKEN)?"<eof>":LATEXT(1),
  695.                 zztokens[tokenWanted]);
  696.         zzconsumeUntil( whatFollows );
  697.         return 0;
  698.     }
  699.     else {
  700.         zzMakeAttr                        
  701. #ifdef DEMAND_LOOK
  702. #ifdef LL_K
  703.         zzdirty++;
  704.         zzlabase++;
  705. #else
  706.         zzdirty = 1;
  707. #endif
  708. #else
  709. /*        zzCONSUME;        /* consume if not demand lookahead */
  710. #endif
  711.         return 1;
  712.     }
  713. }
  714.  
  715. int
  716. #ifdef __USE_PROTOS
  717. _zzsetmatch_wdfltsig(SetWordType *tokensWanted,
  718.                      int tokenTypeOfSet,
  719.                      SetWordType *whatFollows)
  720. #else
  721. _zzsetmatch_wdfltsig(tokensWanted, tokenTypeOfSet, whatFollows)
  722. SetWordType *tokensWanted;
  723. int tokenTypeOfSet;
  724. SetWordType *whatFollows;
  725. #endif
  726. {
  727. #ifdef DEMAND_LOOK
  728. #ifdef LL_K
  729.     if ( zzdirty==LL_K ) {zzCONSUME;}
  730. #else
  731.     if ( zzdirty ) {zzCONSUME;}
  732. #endif
  733. #endif
  734.     if ( !zzset_el((unsigned)LA(1), tokensWanted) )
  735.     {
  736.         fprintf(stderr,
  737.                 "line %d: syntax error at \"%s\" missing %s\n",
  738.                 zzline,
  739.                 (LA(1)==zzEOF_TOKEN)?"<eof>":LATEXT(1),
  740.                 zztokens[tokenTypeOfSet]);
  741.         zzconsumeUntil( whatFollows );
  742.         return 0;
  743.     }
  744.     else {
  745.         zzMakeAttr
  746. #ifdef DEMAND_LOOK
  747. #ifdef LL_K
  748.         zzdirty++;
  749.         zzlabase++;
  750. #else
  751.         zzdirty = 1;
  752. #endif
  753. #else
  754. /*        zzCONSUME;        /* consume if not demand lookahead */
  755. #endif
  756.         return 1;
  757.     }
  758. }
  759.  
  760. int
  761. #ifdef __USE_PROTOS
  762. _zzsetmatch_wsig(SetWordType *e)
  763. #else
  764. _zzsetmatch_wsig(e)
  765. SetWordType *e;
  766. #endif
  767. {
  768. #ifdef DEMAND_LOOK
  769. #ifdef LL_K
  770.     if ( zzdirty==LL_K ) {zzCONSUME;}
  771. #else
  772.     if ( zzdirty ) {zzCONSUME;}
  773. #endif
  774. #endif
  775.     if ( !zzset_el((unsigned)LA(1), e) ) return 0;
  776. #ifdef DEMAND_LOOK
  777. #ifdef LL_K
  778.     zzdirty++;
  779. #else
  780.     zzdirty = 1;
  781. #endif
  782. #endif
  783.     zzMakeAttr
  784.     return 1;
  785. }
  786.  
  787. #ifdef USER_ZZMODE_STACK
  788. static int  zzmstk[ZZMAXSTK] = { -1 };
  789. static int  zzmdep = 0;
  790. static char zzmbuf[70];
  791.  
  792. void
  793. #ifdef __USE_PROTOS
  794. zzmpush( int m )
  795. #else
  796. zzmpush( m )
  797. int m;
  798. #endif
  799. {
  800.    if(zzmdep == ZZMAXSTK - 1) {
  801.      sprintf(zzmbuf, "Mode stack overflow ");
  802.      zzerr(zzmbuf);
  803.    } else {
  804.      zzmstk[zzmdep++] = zzauto;
  805.      zzmode(m);
  806.    }
  807. }
  808.  
  809. void
  810. #ifdef __USE_PROTOS
  811. zzmpop( void )
  812. #else
  813. zzmpop( )
  814. #endif
  815. {
  816.    if(zzmdep == 0)
  817.    {  sprintf(zzmbuf, "Mode stack underflow ");
  818.       zzerr(zzmbuf);
  819.    }
  820.    else
  821.    {  zzmdep--;
  822.       zzmode(zzmstk[zzmdep]);
  823.    }
  824. }
  825.  
  826. void
  827. #ifdef __USE_PROTOS
  828. zzsave_mode_stack( int modeStack[], int *modeLevel )
  829. #else
  830. zzsave_mode_stack( modeStack, modeLevel )
  831. int modeStack[];
  832. int *modeLevel;
  833. #endif
  834. {
  835.   int i;
  836.   memcpy(modeStack, zzmstk, sizeof(zzmstk));
  837.   *modeLevel = zzmdep;
  838.   zzmdep = 0;
  839.     
  840.   return;
  841. }
  842.  
  843. void
  844. #ifdef __USE_PROTOS
  845. zzrestore_mode_stack( int modeStack[], int *modeLevel )
  846. #else
  847. zzrestore_mode_stack( modeStack, modeLevel )
  848. int modeStack[];
  849. int *modeLevel;
  850. #endif
  851. {
  852.   int i;
  853.  
  854.   memcpy(zzmstk, modeStack, sizeof(zzmstk));
  855.   zzmdep = *modeLevel;
  856.     
  857.   return;
  858. }
  859. #endif /* USER_ZZMODE_STACK */
  860.  
  861. #endif /* ERR_H */
  862.